package com.mygdx.game;

import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.PooledEngine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.mygdx.game.components.MovementComponent;
import com.mygdx.game.components.MovementStaticComponent;
import com.mygdx.game.components.PositionComponent;
import com.mygdx.game.components.VisualComponent;
import com.mygdx.game.systems.MovementSystem;
import com.mygdx.game.systems.PlayerControlSystem;
import com.mygdx.game.systems.RenderSystem;

public class BarrageHellMain extends ApplicationAdapter {
	PooledEngine engine;
	
	@Override
	public void create () {
		OrthographicCamera camera = new OrthographicCamera(640, 480);
		camera.position.set(320, 240, 0);
		camera.update();

		Texture crateTexture = new Texture("crate.png");
		Texture coinTexture = new Texture("coin.png");

		engine = new PooledEngine();
		engine.addSystem(new RenderSystem(camera));
		engine.addSystem(new MovementSystem());
		engine.addSystem(new PlayerControlSystem());

		Entity crate = engine.createEntity();
		crate.add(new PositionComponent(320, 240));
		crate.add(new MovementComponent(0, 0));
		crate.add(new VisualComponent(new TextureRegion(crateTexture)));

		engine.addEntity(crate);

		TextureRegion coinRegion = new TextureRegion(coinTexture);

		for (int i = 0; i < 100; i++) {
			Entity coin = engine.createEntity();
			coin.add(new PositionComponent(MathUtils.random(640), MathUtils.random(480)));
			coin.add(new MovementStaticComponent(10, 10));
			coin.add(new VisualComponent(coinRegion));
			engine.addEntity(coin);
		}

	}

	@Override
	public void render () {
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		engine.update(Gdx.graphics.getDeltaTime());
	}
	
	@Override
	public void dispose () {

	}
}
